package model;

import util.ExceptionMethod;

import java.io.Serializable;
import java.util.ArrayList;

public class Student implements Serializable {


    private static final long serialVersionUID = 2187474213863918016L;
    private int id;
    private String name;
    private int age;
    // 一个对象用来存储用户名和密码
    private User user;

    public Student(int id, String name, int age,User user) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.user = user;
    }
    public Student(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;

    }
    public Student(User user){
        this.user = user;
    }


    public Student() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id)  {
        if(id<0||id>20){
            try {
                throw new ExceptionMethod("id不合理哦!");
            } catch (ExceptionMethod exceptionMethod) {
                exceptionMethod.printStackTrace();
            }
        }
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age)  {
        if (age<0||age>120){
            try {
                throw new ExceptionMethod("年纪不合理哦!");
            } catch (ExceptionMethod exceptionMethod) {
                exceptionMethod.printStackTrace();
            }
        }
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

   /* public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<>();
        students.add(new Student(1,"oyz",24));
        students.add(new Student(2,"mz",34));
        students.add(new Student(3,"xyg",25));
        for (Student s: students){
            System.out.println(s);
        }
    }*/
}
